Attribute VB_Name = "modMain"
Dim conn As Object


Private Const sql = "Select Count(id) From question Where id=#ID and InStr(result,'#C')>0"




Sub Main()
    On Error GoTo TheEnd:
    
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fd = fso.GetFolder(Environ("temp"))
    
    Dim sFile As Object
    Dim dDate As Date
    
    For Each v In fd.Files
        If Right(LCase(v.Name), 3) = "htm" Then
            If v.DateCreated > dDate Then
                Set sFile = v
                dDate = v.DateCreated
            End If
        End If
    Next
    PatchFile sFile.Path
    Beep
TheEnd:
End Sub



Sub PatchFile(FileName As String)
    
    Set conn = CreateObject("ADODB.Connection")
    conn.open "Provider=Microsoft.JET.OLEDB.4.0; Data Source=server.mdb"
    
    Dim sTmp As String
    Dim sStart As String
    Dim sEnd As String
    
    Open FileName For Binary As #1
    sTmp = Space(LOF(1))
    Get #1, 1, sTmp
    Close

    Dim f, e As Long
    f = InStr(sTmp, "<body>") + Len("<body>") - 1
    e = InStrRev(sTmp, "</body>")
    sStart = Left(sTmp, f)
    sEnd = Right(sTmp, Len(sTmp) - e + 1)

    Dim oHTML As New HTMLDocument
    oHTML.body.innerHTML = sTmp '
    
    Dim oINPUT As IHTMLElementCollection
    Set oINPUT = oHTML.getElementsByTagName("input")
    
    For Each v In oINPUT
        If conn.execute(Replace(Replace(sql, "#ID", Replace(v.id, "question", "")), "#C", v.Value))(0) > 0 Then
            v.Checked = "checked"
        End If
    Next
    sTmp = oHTML.body.innerHTML
    conn.Close
    Set conn = Nothing
    
    sTmp = sStart & sTmp & sEnd
    
    Open FileName For Output As #1
    Print #1, sTmp
    Close
End Sub



